﻿using System.IO;
using System.Xml.Serialization;

namespace NCql.Parser
{
    [XmlInclude(typeof (SearchClause))]
    [XmlInclude(typeof (BooleanClause))]
    public class CqlQuery
    {
        private PrefixAssignment[] prefixAssignments = new PrefixAssignment[0];
        private SortSpec[] sortSpecs = new SortSpec[0];

        public SortSpec[] SortSpecs
        {
            get { return sortSpecs; }
            set { sortSpecs = value; }
        }

        public PrefixAssignment[] PrefixAssignments
        {
            get { return prefixAssignments; }
            set { prefixAssignments = value; }
        }

        public Clause Clause { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            if (ReferenceEquals(this, obj))
                return true;

            if (GetType() != obj.GetType())
                return false;

            var s1 = new XmlSerializer(GetType());
            var sw1 = new StringWriter();


            s1.Serialize(sw1, this);
            string xml1 = sw1.ToString();

            var s2 = new XmlSerializer(obj.GetType());
            var sw2 = new StringWriter();

            s2.Serialize(sw2, obj);
            string xml2 = sw2.ToString();
            return xml1 == xml2;
        }
    }
}